
rapidjson = require('rapidjson')

function LuaMain()
  self:setTargetLoad(TargetLoad);
  Permission:OpenPermission(100,"android.permission.ACCESS_FINE_LOCATION");
  --Permission:OpenPermission(101,"android.permission.ACCESS_COARSE_LOCATION")
  Canvas = CS.UnityEngine.GameObject.Find("Canvas");
  isCopy = self:Lua_IsCopy();
  logo=self.objectManager:fandGameobject("logo");
  EasyAR_Startup = CS.UnityEngine.GameObject.Find("EasyAR_Startup")
  tt=EasyAR_Startup:GetComponent("AREasyBehavioiur").t;
  VoideObj2=EasyAR_Startup:GetComponent("barCodescannerTest").VoideObj2;

  VoideObj3=VoideObj2.transform:Find("Plane");
  if(CS.UnityEngine.Screen.height>1920)then
  logo.transform.localPosition=CS.UnityEngine.Vector3(-3.8,0,-3.4);
  end
self:loadhttp("/StreamingAssets/Http.txt",function (Httpback)
  print("Httpback-===="..Httpback);
  httpback=Httpback;
    if (Httpback=="0")then
      self._Path._ServerUrl2="https://arapi.xiaomayunkeji.com";
      self._Path._StreamingAssetsName="StreamingAssets";
      tt.text=tt.text.."正式环境";
    end
    if (Httpback=="1")then
      self._Path._ServerUrl2="https://arapi.xiaomayunkeji.com";
      self._Path._StreamingAssetsName="StreamingAssets";
      tt.text=tt.text.."正式环境";
    end
    if (Httpback=="2")then
      self._Path._ServerUrl2="http://www.outiejun.cc:9001";
      --self._Path._StreamingAssetsName="StreamingAssetsTest2";
      self:StreamingAssetsName("StreamingAssetsTest2");
      tt.text=tt.text.."测试环境";
    end
    mainload();
    loadUIcourse();
    loading();
   
      if (Httpback=="3")then
        self._Path._ServerUrl2="https://arapi.xiaomayunkeji.com";
        self._Path._StreamingAssetsName="StreamingAssets";
        if(CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.IPhonePlayer)then
           mainloadui:SetActive(false);
          tt.text=tt.text.."正式环境";
        end
      end
end)

 if(CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.Android)then

end



end 
function mainload()

  local ab=self:Lua_GetBundle("loading","loading",isCopy);
 
  mainloadui = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("loading").gameObject).gameObject;
  mainloadui.transform:SetParent(Canvas.transform);
  MainLoadManager=mainloadui:AddComponent(typeof(CS.MainLoadManager));
  self.objectManager:AddModularGameObject("loading",mainloadui);
  LoadUI=self.objectManager:fandGameobject("loading").transform:Find("Load").gameObject;
  Text=LoadUI.transform:Find("Text").gameObject;
  Text:GetComponent("Text").text="检查更新中。。。";
  
  local mainloaduiTransform=mainloadui:GetComponent("RectTransform");
  mainloaduiTransform.localScale=CS.UnityEngine.Vector3.one;
  mainloaduiTransform.sizeDelta=CS.UnityEngine.Vector2(0,0);
  mainloaduiTransform.localPosition=CS.UnityEngine.Vector3.zero;
  mainloaduiTransform:SetSiblingIndex(999);
  mainloadui:SetActive(false);
 self:SetUpdateImage(Progress)
  
end

function loadUIcourse()
 

  ab=self:Lua_GetBundle("ui","course",isCopy);
 Course = CS.UnityEngine.Object.Instantiate(ab:LoadAsset("course").gameObject).gameObject;
 Course.transform:SetParent(Canvas.transform);
 self.objectManager:AddModularGameObject("Course",Course);
 local CourseTransform=Course:GetComponent("RectTransform");
 CourseTransform.localScale=CS.UnityEngine.Vector3.one;
 CourseTransform.sizeDelta=CS.UnityEngine.Vector2(0,0);
   CourseTransform.localPosition=CS.UnityEngine.Vector3.zero;   
   CourseTransform:SetSiblingIndex(1);
   Course:SetActive(true);
   CourseButton=self.objectManager:fandGameobject("Course","Button");
   CourseButton:GetComponent("Button").onClick:AddListener(function() 
       Course:SetActive(false);
       
          self:PlayerPrefs_SetString("isCourse21","false");
   end);
   jiaocheng=self:PlayerPrefs_GetString("isCourse21");
   if (jiaocheng=="false")then
       Course:SetActive(false);
       
   else

   end
   mainloadui:SetActive(true);
   self:Lua_AddLuaScript("/ui/ARupdateUI.lua");
   self:Lua_AddLuaScript("/ui/ARcamerUI.lua");
   if (httpback=="3")then
      print("httpback---"..httpback);
      if(CS.UnityEngine.Application.platform == CS.UnityEngine.RuntimePlatform.IPhonePlayer)then
        --self:Lua_AddLuaScript("/ui/Request.lua");
      else
        self:Lua_AddLuaScript("/ui/Request.lua");
      end
   else
    self:Lua_AddLuaScript("/ui/Request.lua");
   end
  
end

function loading()
  loadingAB=self:Lua_GetBundle("loading","prompt",isCopy);
  PromptUI = CS.UnityEngine.Object.Instantiate(loadingAB:LoadAsset("prompt").gameObject).gameObject;
  PromptUI.transform:SetParent(Canvas.transform);
  self.objectManager:AddModularGameObject("prompt",PromptUI);
  local RectTransform=PromptUI:GetComponent("RectTransform");
  RectTransform.localRotation=CS.UnityEngine.Quaternion.Euler(0,0,0);
  RectTransform.localScale=CS.UnityEngine.Vector3.one;
  RectTransform.sizeDelta=CS.UnityEngine.Vector2(300,250);
  RectTransform.localPosition=CS.UnityEngine.Vector3.zero;
  RectTransform:SetSiblingIndex(1000);
  PromptUI:SetActive(false);
end

function Progress(i,s)

  MainLoadManager:SetMainLoadProgress(s,i,"");
  if(i==s) then
  --mainloadui:SetActive(false);
  end
end
function TargetLoad(i,k,s)
  --Text:GetComponent("Text").text="AR初始化"..i.."/"..k;
  MainLoadManager:SetMainLoadProgress(k,i,"AR初始化");
  if(i==k) then
    mainloadui:SetActive(false);
  end
    
end
function SetPromptUI(Event,t,isFo,Msg)
  PromptUI:SetActive(true)
  local Button02=self.objectManager:fandGameobject("prompt","Button02")
  Button02:SetActive(isFo)
  Button02:GetComponent("Button").onClick:AddListener(
    function()
      PromptUI:SetActive(false)
    end)
  local Button01=self.objectManager:fandGameobject("prompt","Button01")
  Button01:GetComponent("Button").onClick:AddListener(function()
      Event(PromptUI)
    end)
  Button01Text=self.objectManager:fandGameobject("prompt","Button01","Text")
  Button01Text:GetComponent("Text").text=t
  local MsgText=self.objectManager:fandGameobject("prompt","Text")
  MsgText:GetComponent("Text").text=Msg

end
function isUpdate_PromptBack(PromptUI)
  PromptUI:SetActive(false)
end
function LuaUpdate()
if(VoideObj3.transform.localScale.x==16)then
  VoideObj3.transform.localScale=CS.UnityEngine.Vector3(16,3,9)
end


end
